package com.ktdaddy.controller.system;

import com.ktdaddy.request.CreateRoleReq;
import com.ktdaddy.request.QueryAllRoleReq;
import com.ktdaddy.request.RoleQueryReq;
import com.ktdaddy.request.UpdateRoleReq;
import com.ktdaddy.service.RoleService;
import com.ktdaddy.utils.ApiResponse;
import com.ktdaddy.utils.PageResult;
import com.ktdaddy.vo.RoleInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: lujianhao
 * @Description: 角色控制器
 * @Date: 2021/7/20 5:07 下午
 */
@Api(value = "角色相关", tags = {"角色相关"})
@RequestMapping("/whale/system/role")
@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "查询角色列表",notes = "搜索角色列表",httpMethod = "GET")
    @GetMapping("/getRoleListByPage")
    public ApiResponse getRoleListByPage(RoleQueryReq roleQueryReq){
        PageResult pageResult = roleService.getRoleListByPage(roleQueryReq);
        return ApiResponse.ok(pageResult);
    }

    @ApiOperation(value = "创建角色",notes = "创建角色",httpMethod = "POST")
    @PostMapping("/createRole")
    public ApiResponse createRole(@RequestBody @Valid CreateRoleReq createRoleReq){
        boolean result = roleService.createRole(createRoleReq);
        return ApiResponse.ok(result);
    }

    @ApiOperation(value = "删除角色",notes = "删除角色",httpMethod = "GET")
    @GetMapping("/deleteRole")
    public ApiResponse deleteRole(@RequestParam(value = "roleId") Integer id){
        roleService.deleteRole(id);
        return ApiResponse.ok();
    }

    @ApiOperation(value = "更新角色",notes = "更新角色",httpMethod = "POST")
    @PostMapping("/updateRole")
    public ApiResponse updateRole(@RequestBody @Valid UpdateRoleReq updateRoleReq){
        boolean result = roleService.updateRole(updateRoleReq);
        return ApiResponse.ok(result);
    }

    @ApiOperation(value = "设置状态",notes = "设置状态",httpMethod = "POST")
    @GetMapping("/setRoleStatus")
    public ApiResponse setRoleStatus(@RequestParam(value = "id") Integer id, @RequestParam("status") Integer status){
        boolean result = roleService.setRoleStatus(id,status);
        return ApiResponse.ok(result);
    }

    @ApiOperation(value = "获取所有的角色列表",notes = "获取所有的角色列表")
    @GetMapping("/getAllRoleList")
    public ApiResponse getAllRoleList(QueryAllRoleReq queryAllRoleReq){
        List<RoleInfoVO> roleInfoVOList = roleService.getAllRoleList(queryAllRoleReq);
        return ApiResponse.ok(roleInfoVOList);
    }
}
